namespace sorochinska_kl.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                        Role_RoleId = c.Int(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.webpages_Roles", t => t.Role_RoleId)
                .Index(t => t.Role_RoleId);
            
            CreateTable(
                "dbo.Assessments",
                c => new
                    {
                        AssessmentID = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Name = c.String(),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                        CareerGrowthEmpl = c.String(),
                        ProfGrowthEmpl = c.String(),
                        CareerGrowthMng = c.String(),
                        ProfGrowthMng = c.String(),
                        AssesmentStatusID = c.Int(nullable: false),
                        EmployeePerfRatingID = c.Int(nullable: false),
                        AssessmentStatus_AssessmentStatusID = c.Int(),
                    })
                .PrimaryKey(t => t.AssessmentID)
                .ForeignKey("dbo.Employees", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.AssessmentStatus", t => t.AssessmentStatus_AssessmentStatusID)
                .ForeignKey("dbo.EmployeePerfRatings", t => t.EmployeePerfRatingID, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.AssessmentStatus_AssessmentStatusID)
                .Index(t => t.EmployeePerfRatingID);
            
            CreateTable(
                "dbo.Employees",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        ManagerID = c.Int(nullable: false),
                        HRManagerID = c.Int(nullable: false),
                        PositionID = c.Int(nullable: false),
                        DepartmentID = c.Int(nullable: false),
                        OfficeID = c.Int(nullable: false),
                        EmployeeStatusID = c.Int(nullable: false),
                        FirstName = c.String(),
                        LastName = c.String(),
                        StartDate = c.DateTime(nullable: false),
                        WorkPhone = c.String(),
                        CellPhone = c.String(),
                        Email = c.String(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.Positions", t => t.PositionID, cascadeDelete: true)
                .ForeignKey("dbo.Departments", t => t.DepartmentID, cascadeDelete: true)
                .ForeignKey("dbo.Offices", t => t.OfficeID, cascadeDelete: true)
                .ForeignKey("dbo.EmployeeStatus", t => t.EmployeeStatusID, cascadeDelete: true)
                .Index(t => t.PositionID)
                .Index(t => t.DepartmentID)
                .Index(t => t.OfficeID)
                .Index(t => t.EmployeeStatusID);
            
            CreateTable(
                "dbo.Positions",
                c => new
                    {
                        PositionID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.PositionID);
            
            CreateTable(
                "dbo.Departments",
                c => new
                    {
                        DepartmentID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.DepartmentID);
            
            CreateTable(
                "dbo.Offices",
                c => new
                    {
                        OfficeID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Country = c.String(),
                        Region = c.String(),
                        City = c.String(),
                        Address = c.String(),
                    })
                .PrimaryKey(t => t.OfficeID);
            
            CreateTable(
                "dbo.EmployeeStatus",
                c => new
                    {
                        EmployeeStatusID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.EmployeeStatusID);
            
            CreateTable(
                "dbo.EmployeeBasicEducations",
                c => new
                    {
                        EmployeeBasicEducationID = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Name = c.String(),
                        Department = c.String(),
                        Specialty = c.String(),
                        Degree = c.String(),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.EmployeeBasicEducationID)
                .ForeignKey("dbo.Employees", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.Skills",
                c => new
                    {
                        SkillID = c.Int(nullable: false, identity: true),
                        SkillTypeID = c.Int(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.SkillID)
                .ForeignKey("dbo.SkillTypes", t => t.SkillTypeID, cascadeDelete: true)
                .Index(t => t.SkillTypeID);
            
            CreateTable(
                "dbo.SkillTypes",
                c => new
                    {
                        SkillTypeID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.SkillTypeID);
            
            CreateTable(
                "dbo.AssessmentStatus",
                c => new
                    {
                        AssessmentStatusID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.AssessmentStatusID);
            
            CreateTable(
                "dbo.EmployeePerfRatings",
                c => new
                    {
                        EmployeePerfRatingID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.EmployeePerfRatingID);
            
            CreateTable(
                "dbo.DeliveryTasks",
                c => new
                    {
                        DeliveryTaskID = c.Int(nullable: false, identity: true),
                        AssessmentID = c.Int(nullable: false),
                        Name = c.String(),
                        DueDate = c.DateTime(nullable: false),
                        Plan = c.String(),
                        StatusID = c.Int(nullable: false),
                        ApprovedByManager = c.Boolean(nullable: false),
                        MngRatingID = c.Int(nullable: false),
                        EmplRatingID = c.Int(nullable: false),
                        MngRating_RatingID = c.Int(),
                        EmplRating_RatingID = c.Int(),
                    })
                .PrimaryKey(t => t.DeliveryTaskID)
                .ForeignKey("dbo.Assessments", t => t.AssessmentID, cascadeDelete: true)
                .ForeignKey("dbo.GeneralStatus", t => t.StatusID, cascadeDelete: true)
                .ForeignKey("dbo.Ratings", t => t.MngRating_RatingID)
                .ForeignKey("dbo.Ratings", t => t.EmplRating_RatingID)
                .Index(t => t.AssessmentID)
                .Index(t => t.StatusID)
                .Index(t => t.MngRating_RatingID)
                .Index(t => t.EmplRating_RatingID);
            
            CreateTable(
                "dbo.GeneralStatus",
                c => new
                    {
                        StatusID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.StatusID);
            
            CreateTable(
                "dbo.Ratings",
                c => new
                    {
                        RatingID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.RatingID);
            
            CreateTable(
                "dbo.SkillDevPlans",
                c => new
                    {
                        SkillDevPlanID = c.Int(nullable: false, identity: true),
                        AssessmentID = c.Int(nullable: false),
                        SkillLevelID = c.Int(nullable: false),
                        DevWay = c.String(),
                        ActionsToTake = c.String(),
                        DueDate = c.DateTime(nullable: false),
                        StatusID = c.Int(nullable: false),
                        MngComments = c.String(),
                        ApprovedByMng = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.SkillDevPlanID)
                .ForeignKey("dbo.Assessments", t => t.AssessmentID, cascadeDelete: true)
                .ForeignKey("dbo.SkillLevels", t => t.SkillLevelID, cascadeDelete: true)
                .ForeignKey("dbo.GeneralStatus", t => t.StatusID, cascadeDelete: true)
                .Index(t => t.AssessmentID)
                .Index(t => t.SkillLevelID)
                .Index(t => t.StatusID);
            
            CreateTable(
                "dbo.SkillLevels",
                c => new
                    {
                        SkillLevelID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.SkillLevelID);
            
            CreateTable(
                "dbo.UserSkills",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        SkillID = c.Int(nullable: false),
                        SkillLevelID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserId, t.SkillID })
                .ForeignKey("dbo.Employees", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.Skills", t => t.SkillID, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.SkillID);
            
            CreateTable(
                "dbo.webpages_Membership",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        CreateDate = c.DateTime(),
                        ConfirmationToken = c.String(maxLength: 128),
                        IsConfirmed = c.Boolean(),
                        LastPasswordFailureDate = c.DateTime(),
                        PasswordFailuresSinceLastSuccess = c.Int(nullable: false),
                        Password = c.String(nullable: false, maxLength: 128),
                        PasswordChangedDate = c.DateTime(),
                        PasswordSalt = c.String(nullable: false, maxLength: 128),
                        PasswordVerificationToken = c.String(maxLength: 128),
                        PasswordVerificationTokenExpirationDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "dbo.webpages_Roles",
                c => new
                    {
                        RoleId = c.Int(nullable: false, identity: true),
                        RoleName = c.String(maxLength: 256),
                    })
                .PrimaryKey(t => t.RoleId);
            
            CreateTable(
                "dbo.webpages_OAuthMembership",
                c => new
                    {
                        Provider = c.String(nullable: false, maxLength: 30),
                        ProviderUserId = c.String(nullable: false, maxLength: 100),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Provider, t.ProviderUserId })
                .ForeignKey("dbo.webpages_Membership", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.UserSkill",
                c => new
                    {
                        EmployeeID = c.Int(nullable: false),
                        SkillID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.EmployeeID, t.SkillID })
                .ForeignKey("dbo.Employees", t => t.EmployeeID, cascadeDelete: true)
                .ForeignKey("dbo.Skills", t => t.SkillID, cascadeDelete: true)
                .Index(t => t.EmployeeID)
                .Index(t => t.SkillID);
            
            CreateTable(
                "dbo.webpages_UsersInRoles",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        RoleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.webpages_Membership", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.webpages_Roles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.webpages_UsersInRoles", new[] { "RoleId" });
            DropIndex("dbo.webpages_UsersInRoles", new[] { "UserId" });
            DropIndex("dbo.UserSkill", new[] { "SkillID" });
            DropIndex("dbo.UserSkill", new[] { "EmployeeID" });
            DropIndex("dbo.webpages_OAuthMembership", new[] { "UserId" });
            DropIndex("dbo.UserSkills", new[] { "SkillID" });
            DropIndex("dbo.UserSkills", new[] { "UserId" });
            DropIndex("dbo.SkillDevPlans", new[] { "StatusID" });
            DropIndex("dbo.SkillDevPlans", new[] { "SkillLevelID" });
            DropIndex("dbo.SkillDevPlans", new[] { "AssessmentID" });
            DropIndex("dbo.DeliveryTasks", new[] { "EmplRating_RatingID" });
            DropIndex("dbo.DeliveryTasks", new[] { "MngRating_RatingID" });
            DropIndex("dbo.DeliveryTasks", new[] { "StatusID" });
            DropIndex("dbo.DeliveryTasks", new[] { "AssessmentID" });
            DropIndex("dbo.Skills", new[] { "SkillTypeID" });
            DropIndex("dbo.EmployeeBasicEducations", new[] { "UserId" });
            DropIndex("dbo.Employees", new[] { "EmployeeStatusID" });
            DropIndex("dbo.Employees", new[] { "OfficeID" });
            DropIndex("dbo.Employees", new[] { "DepartmentID" });
            DropIndex("dbo.Employees", new[] { "PositionID" });
            DropIndex("dbo.Assessments", new[] { "EmployeePerfRatingID" });
            DropIndex("dbo.Assessments", new[] { "AssessmentStatus_AssessmentStatusID" });
            DropIndex("dbo.Assessments", new[] { "UserId" });
            DropIndex("dbo.UserProfile", new[] { "Role_RoleId" });
            DropForeignKey("dbo.webpages_UsersInRoles", "RoleId", "dbo.webpages_Roles");
            DropForeignKey("dbo.webpages_UsersInRoles", "UserId", "dbo.webpages_Membership");
            DropForeignKey("dbo.UserSkill", "SkillID", "dbo.Skills");
            DropForeignKey("dbo.UserSkill", "EmployeeID", "dbo.Employees");
            DropForeignKey("dbo.webpages_OAuthMembership", "UserId", "dbo.webpages_Membership");
            DropForeignKey("dbo.UserSkills", "SkillID", "dbo.Skills");
            DropForeignKey("dbo.UserSkills", "UserId", "dbo.Employees");
            DropForeignKey("dbo.SkillDevPlans", "StatusID", "dbo.GeneralStatus");
            DropForeignKey("dbo.SkillDevPlans", "SkillLevelID", "dbo.SkillLevels");
            DropForeignKey("dbo.SkillDevPlans", "AssessmentID", "dbo.Assessments");
            DropForeignKey("dbo.DeliveryTasks", "EmplRating_RatingID", "dbo.Ratings");
            DropForeignKey("dbo.DeliveryTasks", "MngRating_RatingID", "dbo.Ratings");
            DropForeignKey("dbo.DeliveryTasks", "StatusID", "dbo.GeneralStatus");
            DropForeignKey("dbo.DeliveryTasks", "AssessmentID", "dbo.Assessments");
            DropForeignKey("dbo.Skills", "SkillTypeID", "dbo.SkillTypes");
            DropForeignKey("dbo.EmployeeBasicEducations", "UserId", "dbo.Employees");
            DropForeignKey("dbo.Employees", "EmployeeStatusID", "dbo.EmployeeStatus");
            DropForeignKey("dbo.Employees", "OfficeID", "dbo.Offices");
            DropForeignKey("dbo.Employees", "DepartmentID", "dbo.Departments");
            DropForeignKey("dbo.Employees", "PositionID", "dbo.Positions");
            DropForeignKey("dbo.Assessments", "EmployeePerfRatingID", "dbo.EmployeePerfRatings");
            DropForeignKey("dbo.Assessments", "AssessmentStatus_AssessmentStatusID", "dbo.AssessmentStatus");
            DropForeignKey("dbo.Assessments", "UserId", "dbo.Employees");
            DropForeignKey("dbo.UserProfile", "Role_RoleId", "dbo.webpages_Roles");
            DropTable("dbo.webpages_UsersInRoles");
            DropTable("dbo.UserSkill");
            DropTable("dbo.webpages_OAuthMembership");
            DropTable("dbo.webpages_Roles");
            DropTable("dbo.webpages_Membership");
            DropTable("dbo.UserSkills");
            DropTable("dbo.SkillLevels");
            DropTable("dbo.SkillDevPlans");
            DropTable("dbo.Ratings");
            DropTable("dbo.GeneralStatus");
            DropTable("dbo.DeliveryTasks");
            DropTable("dbo.EmployeePerfRatings");
            DropTable("dbo.AssessmentStatus");
            DropTable("dbo.SkillTypes");
            DropTable("dbo.Skills");
            DropTable("dbo.EmployeeBasicEducations");
            DropTable("dbo.EmployeeStatus");
            DropTable("dbo.Offices");
            DropTable("dbo.Departments");
            DropTable("dbo.Positions");
            DropTable("dbo.Employees");
            DropTable("dbo.Assessments");
            DropTable("dbo.UserProfile");
        }
    }
}
